package com.yss.datamiddle.controller;

import com.yss.datamiddle.dto.ScoreLevelAddDto;
import com.yss.datamiddle.dto.ScoreLevelDto;
import com.yss.datamiddle.dto.ScoreLevelUpdateDto;
import com.yss.datamiddle.exception.BizException;
import com.yss.datamiddle.service.ScoreLevelService;
import com.yss.datamiddle.vo.PageModel;
import com.yss.datamiddle.vo.RetResponse;
import com.yss.datamiddle.vo.RetResult;
import com.yss.datamiddle.vo.baseinfomaintain.ScoreLevelVo;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @description: 基础信息维护-数据评分管理
 * @create: 2020/7/9 14:01
 * @update: 2020/7/9 14:01
 */

@RestController
@ApiResponses({
        @ApiResponse(code = 403, message = "Forbidden"),
        @ApiResponse(code = 500, message = "Internal Server Error")
})
@Api(value = "ScoreLevelController", tags = "基础信息维护-数据评分管理")
@RequestMapping("/level")
@AllArgsConstructor
@Slf4j
public class ScoreLevelController {
    private ScoreLevelService scoreLevelService;

    @ApiOperation("查询数据评分管理")
    @GetMapping(value = "/getScoreLevelList/{pageNum}/{pageSize}")
    public RetResult<PageModel<ScoreLevelVo>> getScoreLevelList(
            @PathVariable(value = "pageNum") @ApiParam(value = "当前页", required = true) Integer pageNum,
            @PathVariable(value = "pageSize") @ApiParam(value = "每页大小", required = true) Integer pageSize,
            @RequestParam(value = "search") @ApiParam(value = "评分名称levelName") String search) {
        return RetResponse.makeOKRsp(scoreLevelService.getScoreLevelList(pageNum,pageSize,search));
    }

    @ApiOperation("添加数据评分管理")
    @PostMapping(value = "/addScoreLevel")
    public RetResult<Void> addScoreLevel(@Valid @RequestBody ScoreLevelAddDto dto) throws BizException {
        scoreLevelService.addScoreLevel(dto);
        return RetResponse.makeOKRsp();
    }


    @ApiOperation("删除数据评分管理")
    @PostMapping(value = "/deleteScoreLevel")
    public RetResult<Void> deleteScoreLevel(@Valid Integer id) {
        scoreLevelService.deleteScoreLevel(id);
        return RetResponse.makeOKRsp();
    }

    @ApiOperation("修改数据评分管理")
    @PostMapping(value = "/updateScoreLevel")
    public RetResult<Void> updateScoreLevel(@Valid @RequestBody ScoreLevelUpdateDto dto) {
        scoreLevelService.updateScoreLevel(dto);
        return RetResponse.makeOKRsp();
    }

}
